//
//  SelectVC.swift
//  xiaoleservice
//
//  Created by Wenzhe Fan on 2019/6/1.
//  Copyright © 2019年 Wenzhe Fan. All rights reserved.
//

import UIKit

class SelectVC: UIViewController {
    @IBOutlet weak var 信源: UIButton!
    @IBOutlet weak var 服务: UIButton!
    @IBOutlet weak var 建议: UIButton!
    @IBOutlet weak var 选择: UIButton!
    @IBOutlet weak var tipLB: UILabel!
    @IBOutlet weak var mycolletionView: UICollectionView!
    
    var type:LargeType = .信源

    override func viewDidLoad() {
        super.viewDidLoad()
        self.信源.tag = LargeType.信源.rawValue
        self.服务.tag = LargeType.服务.rawValue
        self.建议.tag = LargeType.建议.rawValue
        self.选择.tag = LargeType.选择.rawValue
        // Do any additional setup after loading the view.
    }
    @IBAction func cancelHander(_ sender: UIButton) {
        
    }
    @objc func p() {
        
    }
    
    @IBAction func touchDwonHande(_ sender: UIButton) {
        type = LargeType(rawValue: sender.tag)!
        switch type {
        case .信源:
            tipLB.isHidden = false
            tipLB.text = "一年内提供的服务暂无"
            DispatchQueue.main.asyncAfter(deadline:.now()+5) {
                self.tipLB.isHidden = true
            }
        case .服务:
            tipLB.isHidden = false
            tipLB.text = "一月内提供的服务暂无"
            DispatchQueue.main.asyncAfter(deadline:.now()+5) {
                self.tipLB.isHidden = true
            }
        case .建议:
            tipLB.isHidden = false
            tipLB.text = "一周内提供的服务目前只有:\n\n1.扫码识别,\n\n2.人脸截取"
            DispatchQueue.main.asyncAfter(deadline:.now()+5) {
                self.tipLB.isHidden = true
            }
        case .选择:
            self.dismiss(animated: true, completion: nil)
        }
        
        
    }
    
    
    @IBAction func touchDwonRepeat(_ sender: UIButton) {
        tipLB.isHidden = false
        tipLB.text = "选择声明\n\n 针对小乐服务中的所有提供的服务:   \n\n2.每一项服务都是免费的，\n\n3.每一项服务都尽可能的延长他的使用期\n\n4.每一项服务都尽可能的扩大使用范围  \n\n5.每一项服务都尽可能的降低使用难度"
        DispatchQueue.main.asyncAfter(deadline:.now()+5) {
            self.tipLB.isHidden = true
        }
    }
    
    
    @IBAction func touchDragEnter(_ sender: UIButton) {
        
    }
    
    @IBAction func touchDragExit(_ sender: UIButton) {
        
    }
    
    
    @IBAction func touchDragInSider(_ sender: UIButton) {
        
    }
    
    @IBAction func touchDragOutSider(_ sender: UIButton) {
        
    }
    
    
    @IBAction func touchupInSider(_ sender: UIButton) {
        
    }
    
    
    @IBAction func touchdownOutSider(_ sender: UIButton) {
        
    }
    var  imageNameArr:[String] = ["新能源","电器","租赁","公益","生活","汽车后服务","出行","志愿者","环境保护","IT开发者","衣问题","食问题","心灵鸡汤","天气","扫码"]
}
extension SelectVC:UICollectionViewDelegate,UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return imageNameArr.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "colleccell", for: indexPath) as! ServiceCell
        cell.view.layer.cornerRadius = cell.view.frame.size.width / 4
        cell.view.layer.masksToBounds = true
        cell.img.image = UIImage.init(named: imageNameArr[indexPath.row])
        cell.view.layer.borderColor  = UIColor.white.cgColor
        cell.view.layer.borderWidth = 0.1
        return cell
    }
    func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
        
        if (indexPath.item == self.imageNameArr.count - 1)  || (indexPath.item == self.imageNameArr.count - 2) || (indexPath.item == self.imageNameArr.count - 3){
             NotificationCenter.default.post(name: NSNotification.Name.init("reduceService"), object:imageNameArr[indexPath.row] as String)
            return
        }
        
        tipLB.isHidden = false
        tipLB.text = "\(imageNameArr[indexPath.row])功能暂未开通"
        DispatchQueue.main.asyncAfter(deadline:.now()+5) {
            self.tipLB.isHidden = true
        }
        
    }
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
        if indexPath.item == self.imageNameArr.count - 1 || (indexPath.item == self.imageNameArr.count - 2) || (indexPath.item == self.imageNameArr.count - 3){
               NotificationCenter.default.post(name: NSNotification.Name.init("addService"), object:imageNameArr[indexPath.row] as String)
            return
        }
       
        tipLB.isHidden = false
        tipLB.text = "\(imageNameArr[indexPath.row])功能暂未开通"
        DispatchQueue.main.asyncAfter(deadline:.now()+5) {
            self.tipLB.isHidden = true
        }
    }
    
}

